package com
{

	import mx.controls.Alert;
	import mx.controls.DataGrid;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
  	import mx.rpc.remoting.mxml.RemoteObject;  

	
	public class AmfPhp
	{
		public var myDataGrid:DataGrid;
		
		public function AmfPhp()
		{
			myDataGrid = new DataGrid();
		}
					
		public function executeService():void
		{
			trace('Methode executeServices OK');
			var amfObjectData:RemoteObject = new RemoteObject();
			
			// Parametre
			amfObjectData.source = "dataBase";
			amfObjectData.destination = "amfphp";
			//serv0.endpoint = "http://localhost/ffa/flex/swfModule/amfphp/gateway.php";
			amfObjectData.endpoint = "http://localhost/myDev/ria-project/swfModule/amfphp/gateway.php";
			
			// Succes ou Erreur
			amfObjectData.selectProduct.addEventListener(ResultEvent.RESULT,resultOK);
			amfObjectData.selectProduct.addEventListener(FaultEvent.FAULT,resultKO);
			amfObjectData.selectProduct();
		}
		
		public function resultOK(evt:ResultEvent):void
		{
			trace('Amfphp connexion OK');
			
			myDataGrid.dataProvider = evt.result as Array;
			trace(myDataGrid.dataProvider);
		}
		
		public function resultKO(event:FaultEvent):void
		{
			Alert.show(event.fault.faultString, event.fault.faultCode.toString());
		}
	}
}